/************************* 版权声明 *********************************
 * 
 * 版权所有：Apache License 2.0
 * 
 ************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2009-12-22
 * 创建记录：创建类结构。
 * 
 * 修改者：       修改日期：
 * 修改记录：
 *
 * 修改者：       修改日期：
 * 修改记录：
 * ……
 ************************* To  Do *********************************
 *
 * 1、实现所有未实现的方法（抛出UnsupportedOperationException的方法）。
 * 
 ************************* 随   笔 *********************************
 *
 * 
 * 
 ******************************************************************
 */

package com.realgodo.site.web.user.show;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.show.Show;
import com.realgodo.site.entity.application.show.ShowCatalog;
import com.realgodo.site.entity.application.show.ShowModule;
import com.realgodo.site.service.application.ShowCatalogManager;
import com.realgodo.site.service.application.ShowManager;
import com.realgodo.site.web.user.UserDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/user/show/") })
public class IndexController extends UserDefaultController {

	@Autowired
	private ShowManager showManager;

	@Autowired
	private ShowCatalogManager showCatalogManager;

	private static final long serialVersionUID = -5764199823148169516L;

	private Show show;

	private Page<Show> showPage;

	private List<ShowModule> modules;

	private List<Show> shows;

	public String execute() throws Exception {
		showPage = this.showManager.findShows(super.getSpace().getId(), 16);

		return SUCCESS;
	}

	/**
	 * 载入新增展示
	 * 
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception {
		return "add";
	}

	/**
	 * 持久化一个展示
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception {
		System.out.println("now");
		getShow().setSpace(super.getSpace());
		this.showManager.createShow(getShow(), getModules());
		return "toindex";
	}

	public String web() throws Exception {
		return "web";
	}

	/**
	 * 载入展示管理
	 * 
	 * @return
	 * @throws Exception
	 */
	public String manager() throws Exception {
		shows = this.showManager.findShows(super.getSpace().getId(), 16)
				.getResult();
		return "manager";
	}

	/**
	 * 新增一个视频展示
	 * 
	 * @return
	 * @throws Exception
	 */
	public String viedo() throws Exception {

		return "viedo";
	}

	public String merge() {
		this.showManager.mergeShowManager(shows);
		return "toindex";
	}

	public Show getShow() {
		return show;
	}

	public void setShow(Show show) {
		this.show = show;
	}

	public List<ShowModule> getModules() {
		return modules;
	}

	public void setModules(List<ShowModule> modules) {
		this.modules = modules;
	}

	public Page<Show> getShowPage() {
		return showPage;
	}

	public void setShowPage(Page<Show> showPage) {
		this.showPage = showPage;
	}

	public List<Show> getShows() {
		return shows;
	}

	public void setShows(List<Show> shows) {
		this.shows = shows;
	}

	public List<ShowCatalog> getShowCatalogs() {
		return this.showCatalogManager.getAll();
	}
}
